<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layouts/layout}">
<!-- BEGIN HEAD -->
<head>
    <title>短信模板编辑</title>
    <link rel="stylesheet" type="text/css"
          href="/assets/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css"/>
    <link rel="stylesheet" type="text/css" href="/assets/plugins/bootstrap-timepicker/compiled/timepicker.css"/>
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body class="page-header-fixed">
<th:block layout:fragment="content">
    <!-- BEGIN PAGE CONTAINER-->
    <div class="container-fluid">
        <!-- BEGIN PAGE HEADER-->
        <div class="row-fluid">
            <div class="span12">
                <!-- BEGIN SAMPLE FORM PORTLET-->
                <div class="portlet ">
                    <div class="portlet-body form">
                        <div th:class="${error != null ? 'alert alert-error' : 'alert alert-error hide'}">
                            <button class="close" data-dismiss="alert"></button>
                            <span th:text="${error}"></span>
                        </div>
                        <div class="row-fluid">
                            <form action="#" id="tform" class="form-horizontal">
                                <input type="hidden" id="id" name="id" th:field="*{template.id}">
                                <input type="hidden" id="sysVersion" name="sysVersion"
                                       th:field="*{template.sysVersion}">
                                <div class="control-group">
                                    <label class="control-label"><span class="required">*</span>模板内容：</label>
                                    <div class="controls">
                                        <textarea id="content" name="content" cols="100" rows="10"
                                                  th:field="*{template.content}"></textarea>
                                    </div>
                                </div>
                                <div class="form-actions">
                                    <button type="button" onclick="update()" class="btn blue">保存</button>
                                    <a type="button" th:href="@{javascript:history.go(-1);}" class="btn">返回</a>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <!-- END SAMPLE FORM PORTLET-->
            </div>
        </div>
        <!-- END PAGE CONTENT-->
    </div>
</th:block>
<th:block layout:fragment="content-js">
    <script type="text/javascript"
            th:src="@{/assets/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js}"></script>
    <script type="text/javascript"
            th:src="@{/assets/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.zh-CN.js}"></script>
    <script type="text/javascript" th:src="@{/assets/plugins/bootstrap-timepicker/js/bootstrap-timepicker.js}"></script>
    <script type="text/javascript">
        function update() {
            var id = $("#id").val();
            var content = $("#content").val();
            var sysVersion = $("#sysVersion").val();
            if (content == "") {
                alert("请输入模板内容");
                return false;
            }
            var param = "content=" + content + "&id=" + id + "&sysVersion=" + sysVersion;
            $.ajax({
                type: 'post',
                url: '/template/update',
                data: param,
                success: function (data) {
                    if (data.code == "0000") {
                        alert(data.msg);
                        window.location.href = "/template/list";
                    } else {
                        alert("保存失败");
                        return false;
                    }
                }
            });
        }
    </script>
</th:block>
</body>
<!-- END BODY -->
</html>